# This module defines
# CRYPTOPP_LIBRARIES
# CRYPTOPP_FOUND
# CRYPTOPP_INCLUDE_DIRS, where to find the headers

option(CRYPTOPP_DLL "Define if you use Crypto++ DLL." OFF)

find_path(CRYPTOPP_INCLUDE_DIRS cryptlib.h)

find_library(CRYPTOPP_DYNAMIC
	NAMES cryptopp cryptdll
)

find_library(CRYPTOPP_STATIC
	NAMES cryptlib
)

if(CRYPTOPP_DLL)
	set(CRYPTOPP_LIBRARIES ${CRYPTOPP_DYNAMIC})
else()
	set(CRYPTOPP_LIBRARIES ${CRYPTOPP_STATIC})
endif()

if(CRYPTOPP_INCLUDE_DIRS)
	file(STRINGS "${CRYPTOPP_INCLUDE_DIRS}/config.h" CRYPTOPP_MAJOR_VERSION REGEX "^#define[ \t]+CRYPTOPP_MAJOR[ \t]+[0-9]+$")
	file(STRINGS "${CRYPTOPP_INCLUDE_DIRS}/config.h" CRYPTOPP_MINOR_VERSION REGEX "^#define[ \t]+CRYPTOPP_MINOR[ \t]+[0-9]+$")
	file(STRINGS "${CRYPTOPP_INCLUDE_DIRS}/config.h" CRYPTOPP_PATCH_VERSION REGEX "^#define[ \t]+CRYPTOPP_REVISION[ \t]+[0-9]+$")
	string(REGEX REPLACE "^[^0-9]+([0-9]+)$" "\\1" CRYPTOPP_MAJOR_VERSION ${CRYPTOPP_MAJOR_VERSION})
	string(REGEX REPLACE "^[^0-9]+([0-9]+)$" "\\1" CRYPTOPP_MINOR_VERSION ${CRYPTOPP_MINOR_VERSION})
	string(REGEX REPLACE "^[^0-9]+([0-9]+)$" "\\1" CRYPTOPP_PATCH_VERSION ${CRYPTOPP_PATCH_VERSION})
	set(CRYPTOPP_VERSION "${CRYPTOPP_MAJOR_VERSION}.${CRYPTOPP_MINOR_VERSION}.${CRYPTOPP_PATCH_VERSION}")
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CryptoPP
	REQUIRED_VARS CRYPTOPP_LIBRARIES CRYPTOPP_INCLUDE_DIRS
	VERSION_VAR CRYPTOPP_VERSION
)

if(CRYPTOPP_DLL)
	add_definitions(-DCRYPTOPP_IMPORTS)
endif()
